package com.xbenben.demo;

import com.xbenben.bean.User;

import java.util.ArrayList;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Stream api
 * xbenben
 * Date:2022/1/15 22:23
 **/
public class StreamDemo {


    private final static ArrayList<User> arrList = new ArrayList<>();


    static {


        arrList.add(new User(Long.valueOf(1), "张三", "北京"));
        arrList.add(new User(Long.valueOf(2), "李四", "天津"));
        arrList.add(new User(Long.valueOf(3), "田七", "北京"));
        arrList.add(new User(Long.valueOf(4), "西瓜", "北京"));


    }


    public static void main(String[] args) {


        //遍历 所有数据 收集为 集合
        // List<String> collect = arrList.stream().map(res -> res.getName()).collect(Collectors.toList());
        //
        // collect.forEach(System.out::println);

        Map<Long, String> collect = arrList.stream().collect(Collectors.toMap(res -> res.getUid(), res -> res.getName()));

        //输出 map 对象
        System.out.println(collect);

        //转为 set  遍历
        collect.entrySet().forEach(System.out::println);


    }


}



